package cn.wolfcode.trip.api.controller;

import cn.wolfcode.trip.base.domain.Signin;
import cn.wolfcode.trip.base.service.ISigninService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
@RequestMapping("signins")
public class SigninController {
    @Autowired
    private ISigninService signinService;
    /**
     * 查找签到表中某用户的最后一条签到记录
     * 资源:/signins
     * 请求方式:get
     * 请求参数:资源占位符(用户的id)
     * 返回结果:Signin
     */
    @GetMapping
    public Signin selectByUserId(Long userId){
    Signin signin = signinService.selectByUserId(userId);
        System.out.println(signin);
        return signin;
    }

    /**
     * 增加签到表中特定用户的数据
     * 资源:/signins
     * 请求方式:put
     * 请求参数:资源占位符(签到对象)
     * 返回结果:JsonResult
     */
    @PostMapping
    public JsonResult saveOrUpdate(Signin signin){
        signinService.saveOrUpdate(signin);
        return new JsonResult();
    }

}
